package com.itcam.ai.config;

import org.springframework.ai.ollama.OllamaEmbeddingModel;
import org.springframework.ai.ollama.api.OllamaApi;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.ai.vectorstore.RedisVectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class VectorStoreConfig {
    @Bean
    public RedisVectorStore.RedisVectorStoreConfig ollamaRedisVectorStoreConfig(){
        return RedisVectorStore.RedisVectorStoreConfig.builder()
                .withURI("redis://47.106.126.154:6479")
                .withIndexName("ollama-qwen2-index")
                .withPrefix("ollama:qwen2:")
                .withMetadataFields(
                        RedisVectorStore.MetadataField.numeric("projectId") // 用于区分不同用户
                )
                .build();
    }
    @Bean
    public RedisVectorStore ollamaRedisVectorStore(){
        return new RedisVectorStore(
                ollamaRedisVectorStoreConfig(),
                new OllamaEmbeddingModel(new OllamaApi(), OllamaOptions.create().withModel("qwen2:7b")),
                true
        );
    }

}
